import * as types from '../_types/order';
import { IReduxOrderInfo, IReduxLastPrice } from '../interface';


export interface IReduxOrder {
    order: {
        [key: string]: IReduxOrderInfo,
    },
    orderRecord: Array<IReduxLastPrice>,
}

const initState: IReduxOrder = {
    order: {
        'ETH/BTC': {
            asks: [], 
            bids: [],
        }
    },
    orderRecord: []
}

export default function order(state:IReduxOrder = initState, action: any) {
    const {type, payload} = action;
    switch(type) {
        case types.UPDATE_ORDER_DATA: {
            return {
                ...state,
                payload,
            }
        }
        case types.UPDATE_ORDER_RECORD: {
            const {orderRecord} = state;
            // if (orderRecord.length)
            return {
                ...state,
                payload,
            }
        }
        default: {
            return state;
        }
    }
}